package com.horoscope.astrology.zodiac.signs.free.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.viewpager.widget.ViewPager
import com.google.android.material.tabs.TabLayout
import com.horoscope.astrology.zodiac.signs.free.R
import com.horoscope.astrology.zodiac.signs.free.adapter.ArticlePageFragmentAdapter

/**
 * 趣味文字答题列表 Quizzes
 */
class QuizzesActivity : BaseActivity() {

    private var mAdapter: ArticlePageFragmentAdapter? = null
    private lateinit var tabQuizzes: TabLayout
    private lateinit var mViewPager: ViewPager

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_quizzes)
        initTitleBar(
            this,
            R.id.btn_back_edit_name,
            R.id.text_view_back_title,
            ""
        )
        initView()
    }

    private fun initView() {
        tabQuizzes = findViewById(R.id.tab_quizzes)
        mViewPager = findViewById(R.id.vp_quizzes)

        mAdapter = ArticlePageFragmentAdapter(this@QuizzesActivity, 1, supportFragmentManager)
        mViewPager.adapter = mAdapter
        mViewPager.currentItem = 0
        mViewPager.offscreenPageLimit = 1

        tabQuizzes.setupWithViewPager(mViewPager)

        tabQuizzes.getTabAt(0)!!.customView = getTabView("Newest")
        tabQuizzes.getTabAt(1)!!.customView = getTabView("Hottest")
    }

    // 自定义每个Tab
    private fun getTabView(title: String): View {
        val v = LayoutInflater.from(this@QuizzesActivity).inflate(R.layout.tab_item_view_quiz, null)
        val textView = v!!.findViewById<TextView>(R.id.text_view_tab)
        textView.text = title
        return v
    }

    companion object {
        fun generateIntent(activity: Activity?): Intent {
            return Intent(activity, QuizzesActivity::class.java)
        }
    }
}